import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    activeMenu: [{
      name: '首页',
      path: '/'
    }]
  },
  getters: {
    activeMenu: state => state.activeMenu
  },
  mutations: {
    SET_ACTIVE: (state, data) => {
      if (state.activeMenu.filter(item => item.path === data.path).length <= 0) {
        state.activeMenu.push(data)
      }
    },
    REMOVE_ACTIVE_MENU: (state, name) => {
      const index = state.activeMenu.findIndex(item => item.name === name)
      if (index >= 0) {
        state.activeMenu.splice(index, 1)
      }
    }
  },
  actions: {
  },
  modules: {
  }
})
